/*************************************************************************
> File Name: bfs.cpp
> Author:ZHLH
> Mail:ZHLH_ZHU@163.com
> Created Time: Fri 25 Aug 2017 11:32:29 AM DST
************************************************************************/

#include <iostream>
#include <cstdio>

using namespace std;

struct note
{
    int x;
    int y;
    int step;
    int l;
} queue[2501];

int change[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int head = 0, tail = 0;
int map[5][5];
int n, m;
int cnt_step = 0;
int main()
{
    int tx = 3;
    int ty = 2;         //target position
    int sx = 0, sy = 0; //start position
    //freopen("in.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> map[i][j];
        }
    }

    queue[tail].x = sx;
    queue[tail].y = sy;
    queue[tail].step = cnt_step;
    queue[tail].l = 0;
    tail++;
    map[sx][sy] = 2;

    while (head < tail)
    {
        for (int c = 0; c < 4; c++)
        {
            int nx = queue[head].x + change[c][0];
            int ny = queue[head].y + change[c][1];

            if (nx >= 0 && nx < n && ny >= 0 && ny < m && !map[nx][ny])
            {
                map[nx][ny] = 2;
                queue[tail].x = nx;
                queue[tail].y = ny;
                queue[tail].step = queue[head].step + 1;
                tail++;
                if (nx == tx && ny == ty)
                    goto O; //跳出循环
            }
        }
        head++;
    }
O:
    if (head < tail)
        cout << queue[tail - 1].step;
    else
        cout << "Can't arrival it!";

    return 0;
}
